package com.onesports.intelligent.k12.polarlight.controller.wx.index;

import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.attendance.AttendanceDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.course.CourseScheduleDetailVO;
import com.onesports.intelligent.k12.polarlight.domain.vo.student.StudentAttendanceVO;
import com.onesports.intelligent.k12.polarlight.security.SecurityUtils;
import com.onesports.intelligent.k12.polarlight.service.course.CourseScheduleDetailService;
import com.onesports.intelligent.k12.polarlight.service.student.StudentAttendanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author Wsy
 **/
@Api(tags = "小程序班级相关-API")
@RestController
@RequestMapping(ApiPathConstants.WX_COURSER_SCHEDULE)
@RequiredArgsConstructor
@PreAuthorize("isAuthenticated()")
public class ClassInfoController {

    private final CourseScheduleDetailService courseScheduleDetailService;
    private final StudentAttendanceService studentAttendanceService;

    @ApiOperation("班级详情-查看课表")
    @GetMapping("/view")
    @ApiImplicitParam(name = "classId", value = "班级id", required = true, paramType = "query", dataType = "string")
    public ResponseEntity<List<CourseScheduleDetailVO>> view(@NotBlank(message = "班级id不可为空") String classId) {
        return ResultUtil.success(this.courseScheduleDetailService.view(classId));
    }


    @ApiOperation("会员查看-班级详情-查看课表-学员信息")
    @GetMapping("/vip-schedule-stu-info")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "时段明细id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "classId", value = "班级id", required = true, paramType = "query", dataType = "string")
    })
    public ResponseEntity<List<StudentAttendanceVO>> vipScheduleStuInfo(@NotBlank(message = "时段明细id不可为空") String id, String classId) {
        return ResultUtil.success(this.courseScheduleDetailService.vipScheduleStuInfo(id, SecurityUtils.getAccountId(), classId));
    }

    @ApiOperation("教练查看-班级详情-查看课表-学员信息")
    @GetMapping("/coach-schedule-stu-info")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "时段明细id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "classId", value = "班级id", required = true, paramType = "query", dataType = "string")
    })
    public ResponseEntity<List<StudentAttendanceVO>> coachScheduleStuInfo(@NotBlank(message = "时段明细id不可为空") String id, String classId) {
        return ResultUtil.success(this.courseScheduleDetailService.coachScheduleStuInfo(id, classId));
    }


    @PostMapping("/attendance")
    @ApiOperation("学员考勤")
    public ResponseEntity<String> attendance(@Valid @RequestBody AttendanceDTO dto){
        this.studentAttendanceService.attendance(dto);
        return ResultUtil.success("操作成功");
    }
}
